#ifndef __WINDOW_H__
#define __WINDOW_H__

class CWindow
{
public:
	CWindow()
		: m_lRefCount(1),
		  m_bIsRealized(false),
		  m_hWnd(NULL),
		  m_iWindowWidth(0),
		  m_iWindowHeight(0)
	{}
	virtual ~CWindow();

	ULONG AddRef()
	{
		return InterlockedIncrement(&m_lRefCount);
	}

	ULONG Release()
	{
		if (InterlockedDecrement(&m_lRefCount) == 0L) 
		{
			delete this;
			return 0L;
		}

		return m_lRefCount;
	}

	LPCTSTR GetClassName();

	LPCTSTR GetWindowName();

	bool Realize(HINSTANCE hInstance);

	void Unrealize();

	virtual void Update();

	virtual int Run(HINSTANCE hInstance,
					 HINSTANCE hPrevInstance,
					 LPTSTR lpCmdLine,
					 int nCmdShow);

	virtual void Quit();

	virtual void Display();

	virtual void KeyDown(WPARAM wVirtualKeyCode,
						 LPARAM lKeyData);

	virtual void KeyUp(WPARAM wVirtualKeyCode,
					   LPARAM lKeyData);

	virtual void KeyCtrl(char keyCtrl)=0;

	HWND	GetWindowHandle()
	{return m_hWnd; }

protected:
	virtual LPCTSTR GetName();
	virtual bool Initialize();
	virtual void Terminate();
	
private:
	LONG m_lRefCount;
	bool m_bIsRealized;
	int m_iWindowWidth;
	int m_iWindowHeight;
	HWND m_hWnd;
};

extern CWindow* g_pWindow;

extern LRESULT CALLBACK WindowProc(HWND hWnd,
									UINT uMsg,
									WPARAM wParam,
									LPARAM lParam);


#endif